import { http } from '@/utils'

// 发布或编辑文章或存为草稿
export const updateArticle = (data, isDraft, isEdit) => {
  return async () => {
    if (isEdit) {
      await http.put(`/mp/articles/${data.id}?draft=${isDraft}`, data)
    } else {
      await http.post(`/mp/articles?draft=${isDraft}`, data)
    }
  }
}

// 根据id获取文章详情
export const getArticleById = (id) => {
  return async () => {
    const res = await http.get(`/mp/articles/${id}`)
    const {
      title,
      channel_id,
      content,
      cover: { type, images },
    } = res.data.data
    return {
      id,
      title,
      channel_id,
      content,
      type,
      images,
    }
  }
}
